$(function () {

    $("#nav_left_btn").click(function () {
        window.location.href = "invite"
    });


    $(".amount_list").find("button").click(function () {
        $(".choose_active").addClass("amount_list_button").removeClass("choose_active");
        $(".choose_active_text").addClass("normal_active_text").removeClass("choose_active_text")
        $(this).addClass("choose_active");
        $(this).find("span").addClass("choose_active_text");
        var vipLevel = $("#vipLevel").val();
        var withdrawmoney = $("#withdrawmoney").val(); //可提现最大金额
        var balance = $("#balance").val(); // 可用余额
        var amount = $(this).find("span").text();
        if (parseFloat(amount) > parseFloat(balance)) {
            toast("available balance not enough!");
            return;
        }
        if (vipLevel != 8) {
            if (parseFloat(amount) > parseFloat(withdrawmoney)) {
                $("#vip_div_zz").css("display", "block");
            }
        }

        $("#show_top_text").text(amount);
    })


    $("#select_bank_card").click(function () {
        $("#add_bank_card").css("display", "block");
        initCard();
    })


    $("#add_bank_card").click(function () {
        window.location.href = 'addBank';
    })

    $("#vip_div_zz").click(function () {
        $("#vip_div_zz").css({"display": "none"})
    });

    $("#withdrawal_btn").click(function () {
        var pwd = $("#ispwd").val();
        var mypassword = $("#mypassword").val();
        if (pwd != mypassword) {
            toast("password is wrong!");
            return;
        }
        var amount = $("#show_top_text").text();
        var bankId = $("#bank_id").val();
        var data = {
            amount: amount,
            bankId: bankId
        }
        $.ajax({
            type: "POST",
            url: "../money/withDraw",
            dataType: "json",
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (msg) {
                if (msg.data) {
                    toast("Successful withdraw,Please wait for review");
                } else {
                    toast("Withdrawals exceed VIP level");
                }
            }
        })

    })

    function initCard() {
        $.ajax({
            type: "GET",
            url: "../bank/bankList",
            dataType: "json",
            contentType: "application/json",
            success: function (msg) {
                var f = msg.data;
                var html = "";
                for (var i = 0; i < f.length; i++) {
                    // console.log(f[i].ifscCode)
                    // console.log(f[i].id)
                    html += "<div class=\"van-collapse-item__wrapper mybanks\"  onClick=\"bankClick(this);\"  >\n" +
                        "<div class=\"van-collapse-item__content\">\n" +
                        "<div data-v-0c756157=\"\" class=\"nav_content\" lang=\"" + f[i].id + "\">" + f[i].ifscCode + "</div>\n" +
                        "</div>\n" +
                        "</div>";
                }
                $("#banks").html(html);
            }
        })
    }


})

function bankClick(t) {
    var ifscCode = $(t).find(".nav_content").text();
    var id = $(t).find(".nav_content").attr("lang");
    console.log("id: " + id)
    $("#add_bank_card").css("display", "none");
    $(".mybanks").css("display", "none");
    $("#select_bank").text(ifscCode)
    $("#bank_id").val(id)
}